package com.guigu.test;

import com.guigu.entity.MyFactoryBean;
import com.guigu.entity.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BeanLifeCycle{

    public static void main(String[] args) throws  Exception{

        System.out.println("现在开始初始化容器");
        ApplicationContext factory = new ClassPathXmlApplicationContext("beans.xml");
        System.out.println("容器初始化成功");


        Object bean1 = factory.getBean("myFactoryBean");
        System.out.println("名字为myFactoryBean的bean是" + bean1.getClass());
        Person p = (Person)bean1;
        System.out.println(p.getName());

        Object bean2 = factory.getBean("&myFactoryBean");
        System.out.println("名字为&myFactoryBean的bean是" + bean2.getClass());
        MyFactoryBean bf = (MyFactoryBean)bean2;

        System.out.println(bf.getObject().getName());

        System.out.println("现在开始关闭容器！");
        ((ClassPathXmlApplicationContext) factory).close();
    }
}
